package com.yiwei.jmx.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.yiwei.jmx.R;
import com.yiwei.jmx.api.model.InviteReward;
import com.yiwei.jmx.api.model.InviteRewardIndexModel;
import com.yiwei.jmx.api.model.PirzeListModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class MyRewardAdapter extends ItemAdapter<InviteReward, MyRewardAdapter.DefaultHolder> {


    public MyRewardAdapter(Context context) {
        super(context);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_my_reward, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        InviteReward item = getItem(position);
        holder.txtName.setText(item.phone);
        //是否已拆红包（1：是，0：否）

        if (item.is_open.equals("0")) {
            holder.txtMoney.setVisibility(View.GONE);
            holder.flGetReward.setVisibility(View.VISIBLE);

            holder.txtStatus.setTextColor(0xffFF0030);
            holder.txtStatus.setText("待领取");
        } else {
            holder.txtMoney.setVisibility(View.VISIBLE);
            holder.flGetReward.setVisibility(View.GONE);
            holder.txtMoney.setText(item.money);
            holder.txtStatus.setTextColor(0xff10BC69);
            holder.txtStatus.setText("已领取");
        }
        holder.btnGetReward.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onChooseListener != null) {
                    onChooseListener.onSuccess(item.id);
                }
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_name)
        TextView txtName;
        @BindView(R.id.txt_status)
        TextView txtStatus;
        @BindView(R.id.txt_money)
        TextView txtMoney;
        @BindView(R.id.btn_get_reward)
        SuperButton btnGetReward;
        @BindView(R.id.fl_get_reward)
        FrameLayout flGetReward;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onSuccess(String id);
    }
}
